package com.hex.liyue.usermodule.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hex.liyue.R;


/**
 * 相机和相册的对话框
 */
public class PhotoSelectDialog extends Dialog implements View.OnClickListener {
    private Button photo;
    private Button camera;
    private TextView tv_dialog_cancel;

    public void setOnPhotoListener(OnPhotoListener onPhotoListener) {
        this.onPhotoListener = onPhotoListener;
    }

    private OnPhotoListener onPhotoListener;

    public PhotoSelectDialog(Context context) {
        super(context, R.style.Theme_AppCompat_Dialog_My);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.photo_layout);
        photo = (Button) findViewById(R.id.photo);
        camera = (Button) findViewById(R.id.camera);
        tv_dialog_cancel = (TextView) findViewById(R.id.tv_dialog_cancel);
        photo.setOnClickListener(this);
        camera.setOnClickListener(this);
        tv_dialog_cancel.setOnClickListener(this);
        setCancelable(true);
        getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        getWindow().setGravity(Gravity.CENTER);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.photo:
                dismiss();
                if (onPhotoListener != null) {
                    onPhotoListener.photo();
                }
                break;
            case R.id.camera:
                dismiss();
                if (onPhotoListener != null) {
                    onPhotoListener.camera();
                }
                break;
            case R.id.tv_dialog_cancel:
                dismiss();
                if (onPhotoListener != null) {
                    onPhotoListener.cancel();
                }
                break;
        }
    }

    public interface OnPhotoListener {
        void photo();

        void camera();

        void cancel();
    }
}
